//
//  SceneryListParse.m
//  LocalTravel
//
//  Created by zheng ji on 14-3-15.
//  Copyright (c) 2014年 jxw. All rights reserved.
//

#import "SceneryListParse.h"
@interface SceneryListParse()
{
    NSMutableArray* _sceneryArray;
    NSMutableDictionary* _sceneryDict;
    //NSMutableString* _itemValue;
    NSString* _currentElementName;
    NSString* _totalPage;
    //NSMutableDictionary* _returnDict;
}
@end
@implementation SceneryListParse
-(SceneryListParse*)initWithXmlData:(NSString*)xmlData{
    
    NSXMLParser* parser=[[NSXMLParser alloc] initWithData:[xmlData dataUsingEncoding:NSUTF8StringEncoding]];
    parser.delegate=self;
    parser.shouldProcessNamespaces=NO;
    [parser parse];
    
    return  self;
}
-(void)parserDidStartDocument:(NSXMLParser *)parser{
    _sceneryArray=[[NSMutableArray alloc]init];
    
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
    _currentElementName=elementName;
    
    if([_currentElementName isEqualToString:@"sceneryList"]){
        _totalPage=[attributeDict objectForKey:@"totalPage"];
       // NSLog(@"%@",str);
        
    }
    
    if([_currentElementName isEqualToString:@"scenery"]){
        _sceneryDict=[[NSMutableDictionary alloc]init];
    }
    //_itemValue=[[NSMutableString alloc]init];
    
    
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
    
    if([elementName isEqualToString:@"scenery"]){
        
        [_sceneryArray addObject:_sceneryDict];
        _sceneryDict=nil;
    }
   
   // _itemValue=nil;
    
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)value{
    if([_currentElementName isEqualToString:@"sceneryName"]){
        [_sceneryDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"imgPath"]){
        [_sceneryDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"sceneryId"]){
        [_sceneryDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"sceneryAddress"]){
        [_sceneryDict setObject:value forKey:_currentElementName];
    }
    
    if([_currentElementName isEqualToString:@"scenerySummary"]){
        [_sceneryDict setObject:value forKey:_currentElementName];
    }
    
    if([_currentElementName isEqualToString:@"cityId"]){
        [_sceneryDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"cityName"]){
        [_sceneryDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"commentCount"]){
        [_sceneryDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"amountAdv"]){
        [_sceneryDict setObject:value forKey:_currentElementName];
    }
    
    
    
}
-(void)parserDidEndDocument:(NSXMLParser *)parser{
    
}
-(void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{
    
}
-(NSMutableDictionary*) getScenaryList{
    NSMutableDictionary* dict=[NSMutableDictionary dictionaryWithObjectsAndKeys:_totalPage,@"totalPage",_sceneryArray,@"sceneryArray", nil];
    return dict;//_sceneryArray;
}
@end
